package org.example.my.model;

import lombok.Data;
import org.example.my.enums.ResultState;

@Data
public class Result {
    private ResultState code;
    private String errMessage;
    private Object data;

    // 成功
    public static Result success(Object data) {
        Result result = new Result();
        result.setCode(ResultState.Success);
        result.setData(data);
        result.setErrMessage("");
        return result;
    }

    // 失败
    public static Result fail(String errMessage) {
        Result result = new Result();
        result.setCode(ResultState.Fail);
        result.setData(null);
        result.setErrMessage(errMessage);
        return result;
    }

    public static Result fail(Object data, String errMessage) {
        Result result = new Result();
        result.setCode(ResultState.Fail);
        result.setData(data);
        result.setErrMessage(errMessage);
        return result;
    }

    public static Result fail(Object data, String errMessage, ResultState code) {
        Result result = new Result();
        result.setCode(code);
        result.setData(data);
        result.setErrMessage(errMessage);
        return result;
    }
}
